package com.design.future;

public class FutureData implements Data {
    RealData realData = null; // FutureData??RealData????
    boolean isReady = false; // ???????????

    public synchronized void setRealData(RealData realData) {
        if (isReady) {
            return;
        }
        this.realData = realData;
        isReady = true;
        notifyAll(); // RealData????????FutureData???????getResult()????
    }

    @Override
    public String getResult() throws InterruptedException {
        if (!isReady) {
            wait(); // ?????RealData???FutureData??
        }
        return realData.getResult();
    }
}
